#include <stdlib.h>  
#include <stdio.h>  
#include <Windows.h>
#include <process.h>

// This demonstrates the observer design pattern
// Here we decouple the code by using seperate event and eventhandler code
// We register one or more observers and they watch a subject for a predefined change
// When a change occures a event function is called and a event is fired
// The event is then handled by one or more objects and this means or more objects call 
// a eventhandler function

// Eventhandler definition
struct EventHandler{
	// Variable to keep track of the number of observers
	int NumberOfObservers;

	// Array of pointer functions (return type void, parameter integer)
	void(*ListOfObservers[10])(int);

	// Boolean that represents a sensor that can be triggerd
	bool Sensor;

	// A mutex handle (a pointer to the mutex)
	HANDLE ghMutex;
};

// Function to initialize a handler 
int InitEventHandler(EventHandler *Handler, void(*HandlerFunction)(int));

// Function to register a event handler function
void RegisterObserver(EventHandler *Handler, void(*HandlerFunction)(int));

// Update function, this function should be called when the observed object (the event handler) 
// changes status. With this function call to fire a event to notify the observer objects that
// handle the actual events
void UpdateHandler(EventHandler *Handler, int Value);

// This function should be part of a seperate software component
// A example could be a printer component, a function is called 
// for example when there is a paper jam event
void HandlerFunction(int Value);

// Worker thread function, this thread function checks if a event had been fired
// if this is true then the event will be handled by one or more event handler functions (observers)
unsigned __stdcall WorkerThreadFunction(void* Data);

// Application command thread funciton
unsigned __stdcall CommandThreadFunction(void* Data);